using System;

namespace JK.EventRouter.Eventing
{
    /// <summary>Allow invocations of <see cref="Action{T}"/> to happen on whatever the current thread is (typically from the thread pool) </summary>
    ///<remarks>Accepts an argument of type T</remarks>
    public class BackgroundThreadAction<T> : IAction<T>
    {
        private readonly Action<T> _myAction;

        public BackgroundThreadAction(Action<T> myAction)
        {
            _myAction = myAction;
        }

        public void Act(T item)
        {
            _myAction(item);
        }
    }

    /// <summary>Allow invocations of <see cref="Act"/> to happen on whatever the current thread is (typically from the thread pool) </summary>
    /// <remarks>An argument-less signature</remarks>
    public class BackgroundThreadAction : IAction
    {
        private readonly Act _myAction;

        public BackgroundThreadAction(Act myAction)
        {
            _myAction = myAction;
        }

        public void Act()
        {
            _myAction.Invoke();
        }
    }
}